{template 'common/header-storex'}
<div class="wn-main wn-main--without">
	<div class="wn-main__head">订单管理</div>
	<div class="wn-main__content">
		<div class="wn-tabs">
			{loop $order_status $status $info}
			<div class="wn-tabs__item {if $_GPC['status'] == $status}wn-tabs__item--active{/if}">
				<a class="wn-tabs__link" href="{php echo $this->createWebUrl('shop_order', array('op' => 'display', 'status' => $status, 'storeid' => $_GPC['storeid']))}">{$info['name']}({$info['num']})</a>
			</div>
			{/loop}
		</div>
		<div class="modal fade" id="quantity-modal" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">修改订单价格</h4>
					</div>
					<div class="modal-body clearfix form-horizontal">
						<input type="number" class="form-control" name="sum_price" />
						<div class="help-block">价格为0.01到99999999.99,精度为两位小数</div>
						<input type="hidden" name="order_id">
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
						<button type="button" class="btn btn-primary" onclick="check_price();">确定</button>
					</div>
				</div>
			</div>
		</div>
		<div class="panel wn-panel">
			<div class="panel-heading">筛选</div>
			<div class="panel-body">
				<form action="./index.php" method="get" class="form-horizontal" role="form">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="m" value="wn_storex" />
				<input type="hidden" name="do" value="shop_order" />
				<input type="hidden" name="status" value="{$_GPC['status']}" />
				<input type="hidden" name="storeid" value="{$storeid}" />
				<div class="form-group">
					<div class="col-sm-1">
						<select name="search_name" class="form-control">
							<option value="roomtitle" {if $_GPC['search_name'] == 'roomtitle'} selected = "selected" {/if}>商品名称</option>
							<option value="realname" {if $_GPC['search_name'] == 'realname'} selected = "selected" {/if}>用户</option>
							<option value="mobile" {if $_GPC['search_name'] == 'mobile'} selected = "selected" {/if}>手机号</option>
							<option value="ordersn" {if $_GPC['search_name'] == 'ordersn'} selected = "selected" {/if}>订单编号</option>
						</select>
					</div>
					<div class="col-sm-2">
						<input class="form-control" name="keyword"  type="text" value="{$_GPC['keyword']}" placeholder="请输入搜索的内容">
					</div>
				</div>
				<div class="form-group">
						<label class="col-sm-1 control-label">订单状态</label>
						<div class="col-sm-3 col-xs-12">
							<select name="paystatus" class="form-control">
								<option value="">支付状态</option>
								<option value="2" {if $_GPC['paystatus'] == '2'} selected = "selected" {/if}>未支付</option>
								<option value="1" {if $_GPC['paystatus'] == '1'} selected = "selected" {/if}>已支付</option>
							</select>
						</div>
				</div>
				<div class="form-group">
					<label class="col-sm-1 control-label">订单时间</label>
					<div class="col-sm-3 col-xs-12">
						{if !empty($_GPC['date'])}
							{php echo tpl_form_field_daterange('date', $_GPC['date'])}
						{else}
							{php echo tpl_form_field_daterange('date', array('start' => date('Y-m-d', time() - 30 * 86400), 'end' => date('Y-m-d', time())))}
						{/if}
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-2 col-sm-offset-1">
						<button class="btn btn-default"><i class="fa fa-search"></i>搜索 </button>
						<button name="export" value="export" class="btn btn-default"><i class="fa fa-download"></i> 导出数据</button>
					</div>
				</div>
			</form>
			</div>
		</div>
		<table  class="table wn-table wn-table--order">
			<col>
			<col width="120px" />
			<col width="180px" />
			<col width="180px" />
			<col width="120px" />
			<col width="150px" />
			<col width="200px" />
			<thead>
			<tr class="wn-table--border text-center">
				<th class="wn-table--left">商品</th>
				<th class="text-center">数量</th>
				<th class="text-center">买家</th>
				<th class="text-center">下单时间</th>
				<th class="text-center">订单状态</th>
				<th class="text-center">实付金额</th>
				<th></th>
			</tr>
			</thead>
			{if empty($show_order_lists)}
			<tr class="wn-table__separation">
				<td colspan="7">暂无订单。。</td>
			</tr>
			{else}
			{loop $show_order_lists $row}
			<tbody>
			<tr class="wn-table__separation">
				<td colspan="7"></td>
			</tr>
			<tr class="wn-table--border wn-table--order__head">
				<td colspan="6">
					<p>
						订单编号：{$row['ordersn']}
						<span class="text-primary">{$row['paytype_text']}</span>
					</p>
					{if $row['uniontid']} <p>商户订单号：{$row['uniontid']}</p> {/if}
				</td>
				<td class="text-center">
					<a href="{php echo $this->createWebUrl('shop_order', array('op' => 'edit', 'id' => $row['id'], 'roomid' => $row['roomid'], 'storeid' => $storeid)); }" class="color-default">查看详情</a>
				</td>
			</tr>
			<tr class="wn-table--border text-center">
				<td class="wn-table--border text-left">
					<img src="{$row['thumb']}" alt="商品图片" style="width: 90px; height: 90px">
					{if !empty($row['roomtitle'])}
					{$row['roomtitle']}
					{else}
					{$row['style']}
					{/if}
				</td>
				<td class="wn-table--border">{$row['nums']}</td>
				<td class="wn-table--border">
					{$row['contact_name']}
					<br/>
					{$row['mobile']}
				</td>
				<td class="wn-table--border"><span data-toggle="tooltip" data-placement="bottom" data-html="true" {if $store_type == STORE_TYPE_HOTEL && isset($row['is_house']) && $row['is_house'] == 1}title="到店时间:{php echo date("Y-m-d", $row['btime']); }<br/>离店时间:{php echo date("Y-m-d", $row['etime']); }"{/if}>{php echo date("Y-m-d H:i:s", $row['time']); }</span></td>
				<td class="wn-table--border">
					<span class="label label-info">{$row['status_text']}</span><br/>
				</td>
				<td class="wn-table--border">{$row['sum_price']}</td>
				<td class="text-left">
					<div class="wn-table__link">
						{if !empty($printer_plugin_status)}
						<div class="dropdown" style="display: inline-block">
							<a id="dLabel" data-target="#" href="#" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="wn-table__link__item">打印小票</i></a>
							<ul class="dropdown-menu" aria-labelledby="dLabel">
								{if !empty($printers)}
									{loop $printers $p}
									<li><a onclick="return confirm('是否打印小票?');return false;" href="{php echo $this->createWebUrl('shop_order', array('op' => 'print_order', 'id' => $row['id'], 'print' => $p['id'], 'storeid' => $storeid))}">{$p['name']}</a></li>
									{/loop}
								{else}
									<li><a href="{php echo $this->createWebUrl('shop_order', array('op'=>'check_print_plugin', 'storeid' => $storeid))}" target="_blank">添加打印机</a></li>
								{/if}
							</ul>
						</div>
						{/if}
						{if $row['status'] != -1 && $row['status'] != 3 && $row['status'] != 2 && $row['paystatus'] == 0}
						<a href="javascript:;" class="wn-table__link__item change_price" data-id="{$row['id']}" data-price="{$row['sum_price']}">修改总价</a>
						{/if}
						<a onclick="return confirm('此操作不可恢复，取消删除吗?');return false;" href="{php echo $this->createWebUrl('shop_order', array('op' => 'delete', 'id' => $row['id'], 'storeid' => $storeid, 'roomidid' => $row['roomid']))}" class="wn-table__link__item">删除</a>
					</div>
				</td>
			</tr>
			</tbody>
			{/loop}
			{/if}
		</table>
		<div class="clearfix"></div>
		<div class="pull-right">
			{$pager}
		</div>
	</div>
</div>
<script type="text/javascript">
	require(['bootstrap'],function($) {
		$("[data-toggle='tooltip']").tooltip();
	});
	
	$(function(){
		$('.check_all').click(function() {
			var checked = $(this).get(0).checked;
			$(':checkbox').each(function() {
				this.checked = checked;
			});
		});
		$('input[name=deleteall]').click(function() {
			var check = $('input:checked');
			if(check.length<1){
				util.message('请选择要删除的记录!');
				return;
			}
			if(confirm("确认要删除选择的记录?")){
				var id = new Array();
				check.each(function(i) {
					id[i] = $(this).val();
				});
				$.post("{php echo $this->createWebUrl('shop_order',array('op' => 'deleteall', 'storeid' => $storeid))}", {idArr:id}, function(data) {
					if (data.message.errno ==0) {
						util.message(data.message.message, 'refresh', 'success');
					} else {
						util.message(data.message.message);
					}
				},'json');
			}

		});
	});
	$('.change_price').click(function() {
		order_id = $(this).data('id');
		$('input[name="order_id"]').val(order_id);
		$('#quantity-modal').modal();
	});

	function drop_confirm(msg, url) {
		if (confirm(msg)) {
			window.location = url;
		}
	}
	
	function check_price() {
		var price = $('input[name=sum_price]').val();
		var orderid = $('input[name=order_id]').val();
		price = Number(price);
		if (price < 0.01 || price > 99999999.99) {
			util.message('价格错误！', 'refresh', 'error');
			return;
		} else {
			$.post("{php echo $this->createWebUrl('shop_order', array('op' => 'edit_price', 'storeid' => $storeid))}", {sum_price:price, id:orderid}, function(data) {
				if (data.message.errno == 0) {
					util.message(data.message.message, 'refresh', 'success');
					return;
				} else {
					util.message(data.message.message);
					return;
				}
			},'json');
		}
	}
</script>
{template 'common/footer'}